<?php

namespace App\Admin\Extensions\Tools;

use Encore\Admin\Grid\Tools\BatchAction;

/**
 *角色列表view层组件逻辑.
 */
class PlayerAction extends BatchAction
{
    protected $status;

    public function __construct($status = 1)
    {
        $this->status = $status;
    }

    /**
     * [script js代码].
     *
     * @Author   王文凡
     * @DateTime 2018-03-01
     *
     * @version  1.0
     *
     * @return [type] [description]
     */
    public function script()
    {
        $tips = trans('game.select_role');
        return <<<EOT
$('{$this->getElementClass()}').on('click', function() {
    var playerIds = selectedRows();
    if(playerIds == ''){
        swal("{$tips}");return;
    }

    if('{$this->status}' == 2){
        //封角色
        $('#forbid-modal').modal();
        return false;
    }
    swal({
      title: "确定要执行？",
      text: "执行后将无法恢复！",
      type: "warning",
      showCancelButton: true,
      confirmButtonColor: "#DD6B55",
      confirmButtonText: "确定",
      cancelButtonText: "取消"
    },
    function(){
        if('{$this->status}' == 1){
            //踢角色下线
                var param = {
                    type:'post',
                    url:'{$this->resource}/kicking',
                    data:{
                        _token:LA.token,
                        ids:playerIds,
                        status: {$this->status},
                        serverid:getPar('serverid')
                    },
                    success:function(data){
                         $.pjax.reload('#pjax-container');
                         $(".close").click();
                         toastr.success(data.message);
                    }
            };
             ajaxHttp(param);
        }
    });

});


EOT;
    }
}
